package com.admin.business.background.venusOrgAdapay;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 企业在汇付开通的账户
 * @create: 2023-10-30 14:35:25
 **/
@Service("venusOrgAdapayService")
@Slf4j
public class VenusOrgAdapayService{

    @Resource
    VenusOrgAdapayDao venusOrgAdapayDao;

    /**
     * 添加企业在汇付开通的账户,获取id数据
     *
     * @param cdoRequest - id:
     *                   - org_id:账本ID
     *                   - order_no:请求订单号
     *                   - member_id:商户下的用户id
     *                   - sys_user:操作人
     *                   - create_time:操作时间
     *                   - bank_code:收款银行
     *                   - bank_acct_type:银行账户类型
     *                   - card_no:银行卡号
     *                   - card_name:银行卡户名
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return addVenusOrgAdapay(CDO cdoRequest) {
        venusOrgAdapayDao.addVenusOrgAdapay(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新企业在汇付开通的账户数据
     *
     * @param cdoRequest - id:
     *                   - org_id:账本ID
     *                   - order_no:请求订单号
     *                   - member_id:商户下的用户id
     *                   - sys_user:操作人
     *                   - create_time:操作时间
     *                   - bank_code:收款银行
     *                   - bank_acct_type:银行账户类型
     *                   - card_no:银行卡号
     *                   - card_name:银行卡户名
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return updateVenusOrgAdapayById(CDO cdoRequest) {
        venusOrgAdapayDao.updateVenusOrgAdapayById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除企业在汇付开通的账户数据
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return deleteVenusOrgAdapayById(CDO cdoRequest){
        int count = venusOrgAdapayDao.deleteVenusOrgAdapayById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除企业在汇付开通的账户数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return deleteVenusOrgAdapay(CDO cdoRequest) {
        int count = venusOrgAdapayDao.deleteVenusOrgAdapay(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取企业在汇付开通的账户数据
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return getVenusOrgAdapayById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrgAdapayDao.getVenusOrgAdapayById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取企业在汇付开通的账户数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return getVenusOrgAdapayListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrgAdapayDao.getVenusOrgAdapayListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrgAdapayDao.getVenusOrgAdapayCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取企业在汇付开通的账户数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-30 14:35:25
     */
    @OpenApi
    public Return getVenusOrgAdapayListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrgAdapayDao.getVenusOrgAdapayListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrgAdapayDao.getVenusOrgAdapayCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
